/**
 * 商品管理-属性管理-一二三级分类仓库
 */
import { defineStore } from "pinia";
import { getC1, getC2, getC3, getAttrInfoList } from '@/api/product/attr/index.ts'
import {categoryList} from '@/api/product/attr/type.ts'

const useCategoryStore = defineStore('categoryStore', {
  state: () => {
    return {
      category1List: [],
      category2List: [],
      category3List: [],
      category1Id: '',
      category2Id: '',
      category3Id: '',
      attrInfoList: []
    }
  },
  actions: {
    async getC1List() {
      const result: categoryList = await getC1()
      const { code, data, message } = result
      if (code == 200) {
        this.category1List = data
        return 'ok'
      } else {
        return Promise.reject(new Error(message))
      }
    },
    async getC2List(id) {
      const result: categoryList = await getC2(id)
      const { code, data } = result
      if (code == 200) {
        this.category2List = data
      }
    },
    async getC3List(id) {
      const result: categoryList = await getC3(id)
      const { code, data } = result
      if (code == 200) {
        this.category3List = data
      }
    },
    async getAttrInfoList(c1Id: number, c2Id: number, c3Id: number) {
      const result = await getAttrInfoList(c1Id, c2Id, c3Id)
      const { code, data } = result
      if (code == 200) {
        this.attrInfoList = data
      }
    }
  },
  getters: {

  }
})
export default useCategoryStore;